package com.tree.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tree.backend.entity.pojo.BudgetConfig;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 部门预算配置表 Mapper 接口
 * </p>
 */
public interface BudgetConfigMapper extends BaseMapper<BudgetConfig> {

    /**
     * 根据年份和条件获取按部门统计的预算分析数据
     */
    @Select("SELECT department_id as name, SUM(budget_amount) as budgetAmount FROM budget_config WHERE budget_year = #{year} " +
            "${departmentIdCondition} GROUP BY department_id")
    List<Map<String, Object>> getDepartmentBudgetAnalysis(@Param("year") Integer year, @Param("departmentIdCondition") String departmentIdCondition);

    /**
     * 根据年份和条件获取按成本项目统计的预算分析数据
     */
    @Select("SELECT cost_item_id as name, SUM(budget_amount) as budgetAmount FROM budget_config WHERE budget_year = #{year} " +
            "${departmentIdCondition} GROUP BY cost_item_id")
    List<Map<String, Object>> getCostItemBudgetAnalysis(@Param("year") Integer year, @Param("departmentIdCondition") String departmentIdCondition);
}
